#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

FILE *infile(int argc,char **argv){
        char commandbuffer[1024];
        FILE *infile;
        if(argc<2){
                fprintf(stderr,"Usage %s <grammar file> <options>\n", argv[0]);
                exit(-2);
        }
        snprintf(commandbuffer,sizeof commandbuffer,"cpp -I/usr/include/nail/generator < \"%s\" |sed '/^\\#/d'",argv[1]);
        infile = popen(commandbuffer,"r");
        if(!infile) error ("Cannot open pipe\n");
        return infile;
}
typedef struct grammar {
}grammar;

typedef struct NailArena{
}NailArena;

grammar * parse_grammar(NailArena *arena, uint8_t *input, size_t size)
{

}

void NailArena_init(NailArena *arena, size_t size){
}

int main(int argc, char**argv)
{
    uint8_t input[102400];
    size_t inputsize;
    size_t outputsize;
    char *out;
    struct grammar *result;

    NailArena arena;
    inputsize = fread(input, 1, sizeof(input), infile(argc,argv));
    NailArena_init(&arena, 4096);
    result =  parse_grammar(&arena,input,inputsize);
    printf("ok");
    return 0;
}
